(function () {
    'use strict';

    angular
        .module('app.NewUser')
        .controller('NewUserController', NewUserController);

    NewUserController.$inject = ['logger','$state','$rootScope','UserContextData','$mdDialog','$timeout'];
    /* @ngInject */
    function NewUserController(logger, $state, $rootScope, UserContextData,$mdDialog,$timeout) {
        var vm = this;
        vm.title = 'NewUser';
        vm.user = "";
        vm.password = "";
        vm.ErrorMessage = "";
        vm.secretans = "";
        vm.NewUserClick = NewUserClick;


        activate();
        function activate() {
        }

  
        function NewUserClick() {


            var promise = UserContextData.AddNewUser(vm.user, vm.password,vm.usertype,vm.fname,vm.lname,vm.secretqn,vm.secretans).then(function (response) {
                    if (response.data.StatusMsg) {
                        vm.ErrorMessage = response.data.StatusMsg;
                        if (response.data.StatusMsg == "User Created") {
                            $mdDialog.show(
                          $mdDialog.alert()
                            .parent(angular.element(document.body))
                            .clickOutsideToClose(true)
                            .title('New User')
                            .textContent(vm.ErrorMessage)
                            .ariaLabel('New User Dialog')
                            .ok('Close')
                        ).then(function (response) {
                            $timeout(function () {
                                $mdDialog.hide();
                                $state.go('login');
                            }, 100);
                        });
                        }
                    }
                })

        }


        function showWait() {
            $mdDialog.show({
                controller: 'LoginController',
                template: '<md-dialog style="background-color:transparent;box-shadow:none">' +
                            '<div layout="row" layout-sm="column" layout-align="center center" aria-label="wait">' +
                                '<md-progress-circular md-mode="indeterminate" class="md-accent"></md-progress-circular>' +
                            '</div>' +
                         '</md-dialog>',
                parent: angular.element(document.body),
                clickOutsideToClose: false,
                fullscreen: false
            })
            .then(function (answer) {

            });
        }
    }
})();